/*
 * @Author: jhy
 * @Date: 2024-07-10 18:00:09
 * @LastEditTime: 2024-07-11 14:25:25
 * @LastEditors: jhy
 * @Description: 
 * @FilePath: /next-admin/src/models/user.js
 */
import mongoose from "mongoose";

const userSchema = new mongoose.Schema({
    email: {
        type: String,
        required: true,
        unique: true,
    },
    pwd: {
        type: String,
        required: true,
    },
    createdAt: {
        type: Date,
        default: new Date(),
    },
    updatedAt: {
        type: Date,
        default: new Date(),
    },
});

userSchema.pre("save", function (next) {
    if (this.isNew) {
        this.createdAt = this.updatedAt = new Date();
    } else {
        this.updatedAt = new Date();
    }
    next();
})

const User = mongoose.models.users || mongoose.model('users', userSchema);

export default User;